package com.jlu155.CourseManager.service;

import com.jlu155.CourseManager.Bean.PageRequest;
import com.jlu155.CourseManager.Bean.PageResult;
import com.jlu155.CourseManager.entity.*;
import com.jlu155.CourseManager.repository.*;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TeachClassService {
    @Autowired
    private TeachClassRepository teachClassRepository;
    @Autowired
    private TeacherRepository teacherRepository;
    @Autowired
    private SessionRepository sessionRepository;
    @Autowired
    private StudentCourseRepository studentCourseRepository;
    @Autowired
    private  StudentCourseService studentCourseService;
    public void associateMult(TeachClass teachClass,boolean withSessions,boolean withStudents){
            if(withSessions){
                List<Session> sessionList=sessionRepository.findSessionsByTcId(teachClass.getTc_id());
                teachClass.setSessionList(sessionList);
            }
            if(withStudents){
                List<StudentCourse> studentList=studentCourseRepository.findStudentCourseByTcId(teachClass.getTc_id());
                teachClass.setStudentCourseList(studentList);
            }
    }
    public PageResult<TeachClass> getTeachClassPage(PageRequest pageRequest){
        PageResult<TeachClass> pageResult=new PageResult<>();
        List<TeachClass> teachClasses;
        teachClasses=teachClassRepository.findTeachClassByTeacherId(pageRequest.getTid());
        int total= teachClasses.size();
        pageResult.setPageList(teachClasses);
        pageResult.cutPage(pageRequest.getIndex(), pageRequest.getSize());
        pageResult.setPageNumber(total);
        return pageResult;
    }
}


